﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Admin;
using BLL;
using BLL.UserInfos;
using BLL.UserInfos.DTO;
using System;
using Microsoft.AspNetCore.Authorization;
using Admin.Service.UserInfos.DTO;
using Microsoft.Extensions.Logging;
using NLog;

namespace Admin.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class UserInfoController : ControllerBase
    {
        private readonly IUserInfoService userInfoBll;
        private readonly ILogger<UserInfoController> logger;
        
        public UserInfoController(IUserInfoService userInfoBll, ILogger<UserInfoController> logger)
        {
            this.userInfoBll = userInfoBll;
            this.logger = logger;
        }

        /// <summary>
        /// 删除 单删
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult Delete(int id)
        {
            return Ok(userInfoBll.Delete(id));
        }

        /// <summary>
        /// 删除 批删
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult DeleteList(int[] id)
        {
            return Ok(userInfoBll.DeleteList(id));
        }

        /// <summary>
        /// 用户信息显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Queryable(int page, int size, string username, DateTime? starttime, DateTime? endtime)
        {
            return Ok(userInfoBll.Queryable(page, size, username, starttime, endtime));
        }

        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="addUserInfoDto"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddUserInfo(AddUserInfoDto addUserInfoDto)
        {
            return Ok(userInfoBll.AddUserInfo(addUserInfoDto));
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="addUserInfoDto"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult UpdUserInfo(AddUserInfoDto addUserInfoDto)
        {
            return Ok(userInfoBll.UpdUserInfo(addUserInfoDto));
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="addUserInfoDto"></param>
        /// <returns></returns>        
        [HttpPost]
        [AllowAnonymous]
        public IActionResult GetLogin(LoginDto loginDto)
        {
            return Ok(userInfoBll.GetLogin(loginDto));
        }
    }
}
